package com.chengdu.chun.mapper;

import com.chengdu.chun.po.Student;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentMapper {
    @Select("select count(*) from student where rid is not null")
    public int getStudentCountByroomTeacher();

    @Select("select count(*) from student where cid in (select cid from classes where uid = #{teacherid} and cstatus = 1)")
    public Integer selectCountByTeacher(int teacherid);

    /**
     * 注解方式定义当前接口需要执行的SQL语句
     *
     * @param classesid
     * @return
     */
    @Select("select * from student where cid = #{cid}")
    public List<Student> getStudentsByClasses(int classesid);

    @Select("select * from student where rid = #{rid}")
    public List<Student> getStudentByRoom(int rid);

    public List<Student> studentsBySnameAndMobile(@Param("cid") long cid, @Param("sname") String sname, @Param("mobile") String mobile);

    @Insert("insert into student values(null,#{sname},#{sex},#{birthday},#{mobile},#{address},#{parentname},#{parentmobile},null,#{cid},now(),1)")
    public int insertStudent(Student student);

    @Select("select sid, sname, sex, birthday, mobile, address, parentname, parentmobile, rid, cid, \n" +
            "    createtime, cstatus from student" +
            "    where sid = #{sid,jdbcType=INTEGER}")
    public Student studentInfoBysid(Integer sid);

    @Update("update student set cstatus=#{cstatus} where sid=#{sid}")
    public int changeStatus(@Param("cstatus") Integer cstatus, @Param("sid") Integer sid);


    int deleteByPrimaryKey(Integer sid);

    int insert(Student record);

    int insertSelective(Student record);

    Student selectByPrimaryKey(Integer sid);

    int updateByPrimaryKeySelective(Student record);

    int updateByPrimaryKeyWithBLOBs(Student record);

    int updateByPrimaryKey(Student record);
}